package edu.sjsu.tweentiment.weight;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.google.gson.*;

import edu.sjsu.tweentiment.obj.*;
import edu.sjsu.tweentiment.util.*;

/**
 * viralheat https://www.viralheat.com/
 * 
 * Let's us make 5000 calls per day
 */
public class WordWeight {

	private final String VIRALHEAT_KEY = "zWYw1AnRhv7oftC7X75E"; // 5000 Calls per day

	public Double getWordWeight(String word) throws IOException {
		String url = "https://www.viralheat.com/api/sentiment/review.json?api_key=" + VIRALHEAT_KEY + "&text=" + word;
		String jsonTxt = NetUtil.httpGet(url);
		// String jsonTxt =
		// "{\"prob\":0.806548944920931,\"mood\":\"positive\",\"text\":\"happy\"}";
		
		//System.out.println("jsonTxt:  " + jsonTxt);

		Gson gson = new Gson();
		WordVH wordVh = gson.fromJson(jsonTxt, WordVH.class);

		Double prob = wordVh.getProb();
		if (wordVh.getMood().equals("negative")) {
			return prob * -1;
		}

		return prob;
	}
	
//	public Boolean isWordNoun(String word) throws IOException {
//		//http://glosbe.com/gapi/translate?from=eng&dest=eng&format=json&phrase=witaj&pretty=true
//		String url = "http://glosbe.com/gapi/translate?from=eng&dest=eng&format=json&phrase=" + word.toLowerCase(); //&pretty=true"
//		String jsonTxt = NetUtil.httpGet(url);
//		Gson gson = new Gson();
//		WordGlosbe wordGlosbe = gson.fromJson(jsonTxt, WordGlosbe.class);
//		List<?> x = wordGlosbe.getTuc();
//		
//		if(x==null || x.size()==0) {
//			return true;
//		}
//		return false; // has meanings
//	}

}
